"use strict";
const common_vendor = require("../common/vendor.js");
const composables_useGlobalMessage = require("../composables/useGlobalMessage.js");
const utils_index = require("../utils/index.js");
const __unplugin_components_0 = () => "../node-modules/wot-design-uni/components/wd-message-box/wd-message-box.js";
if (!Array) {
  const _component_wd_message_box = __unplugin_components_0;
  _component_wd_message_box();
}
const __default__ = {
  options: {
    virtualHost: true,
    addGlobalClass: true,
    styleIsolation: "shared"
  }
};
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  ...__default__,
  __name: "GlobalMessage",
  setup(__props) {
    const { messageOptions, currentPage } = common_vendor.storeToRefs(composables_useGlobalMessage.useGlobalMessage());
    const messageBox = common_vendor.useMessage("globalMessage");
    const currentPath = utils_index.getCurrentPath();
    common_vendor.watch(() => messageOptions.value, (newVal) => {
      if (newVal) {
        if (currentPage.value === currentPath) {
          const option = common_vendor.deepClone(newVal);
          messageBox.show(option).then((res) => {
            if (common_vendor.isFunction(option.success)) {
              option.success(res);
            }
          }).catch((err) => {
            if (common_vendor.isFunction(option.fail)) {
              option.fail(err);
            }
          });
        }
      } else {
        messageBox.close();
      }
    });
    return (_ctx, _cache) => {
      return {
        a: common_vendor.p({
          selector: "globalMessage"
        })
      };
    };
  }
});
wx.createComponent(_sfc_main);
